package atom.core0.global;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;



public class MyProperties
{
	private Map<String,String> map = new HashMap();
	public Map load(InputStream inn,String charset) throws IOException
	{
		InputStreamReader isr = new InputStreamReader(inn,charset);
		BufferedReader lineReader = new BufferedReader(isr);
		while(true)
		{
			String lineContent = lineReader.readLine();
			if (lineContent == null)
			{
				isr.close();
				lineReader.close();
				break;
			}
			lineContent.trim();
			
			if(lineContent.equals(""))
			{
				continue;
			}
			else
			{
				if (lineContent.substring(0, 1).equals("#"))
					continue;
				else
				{
					int pos = lineContent.indexOf("=");
					if(pos>0)
					{
						String key = lineContent.substring(0, pos);
						String value = lineContent.substring(pos+1);
						map.put(key.trim(), value.trim());
					}
				}
			}
		}
		return map;
	}
	public Map getMap()
	{
		return map;
	}
	public Map load(String filename,String charset) throws IOException
	{
		FileInputStream fs = new FileInputStream(filename);
		return load(fs,charset);
	}
}
